/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.fileSystem;

import java.util.Random;

public class FileSystemGenerator {
	private int numFile;
	private int maxFileSize;
	private int minFileSize;
	private int blockSize;
	
	public FileSystemGenerator(int numFile, int maxFileSize, int minFileSize, int blockSize){
		setNumFile(numFile);
		setMaxFileSize(maxFileSize);
		setMinFileSize(minFileSize);
		setBlockSize(blockSize);
	}
	
	public void generate(FileSystem fileSystem, Storer storer){
		Random r = new Random(System.currentTimeMillis());
		for(int i=0; i<numFile; ++i){
			File file = new File("file"+i);
			int fileSize = (int) (minFileSize+(maxFileSize-minFileSize)*r.nextDouble());
			for(int j=0; j<(int)Math.ceil((double)fileSize/blockSize)-1; ++j){
				Block block = new Block(blockSize);
				file.addBlock(block);
			}
			int tail = fileSize%blockSize;
			if(tail == 0){
				Block block = new Block(blockSize);
				file.addBlock(block);
			}else{
				Block block = new Block(tail);
				file.addBlock(block);
			}
			fileSystem.addFile(file);
		}
	}

	public int getNumFile() {
		return numFile;
	}

	public void setNumFile(int numFile) {
		this.numFile = numFile;
	}

	public long getMaxFileSize() {
		return maxFileSize;
	}

	public void setMaxFileSize(int maxFileSize) {
		this.maxFileSize = maxFileSize;
	}

	public int getMinFileSize() {
		return minFileSize;
	}

	public void setMinFileSize(int minFileSize) {
		this.minFileSize = minFileSize;
	}

	public int getBlockSize() {
		return blockSize;
	}

	public void setBlockSize(int blockSize) {
		this.blockSize = blockSize;
	}

}
